<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var obj = {
      id: 1,
      name: 'andy',
    }
    var o = {}
    // for (var k in obj){
    //   o[k] = obj[k]
    // }
    // console.log(o);

    console.log("-------");
    Object.assign(o, obj)
    console.log(o);
    var o = {}

    function deepCopy(newobj, oldobj) {
      for (var k in oldobj) {
        //判断数据类型
        var item = oldobj[k]
        //判断是不是数组.数组要在对象之前判断,因为数组也属于对象
        if (item instanceof Array) {
          newobj[k] = [];
          deepCopy(newobj[k], item)
        } else if (item instanceof Object) {
          newobj[k] = {}
          deepCopy(newobj[k], item)
        } else {
          //简单类型
          newobj[k] = item
        }
      }
    }
  </script>
</body>

</html>